package org.tis.tools.operatelog.module.log.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.LogData;
import org.tis.tools.operatelog.module.log.service.ILogDataService;
import org.tis.tools.starter.mybatisplus.querykit.model.Query;

import javax.validation.constraints.NotBlank;

/**
 * Created by chenchao
 * Created on 2018/6/1 19:33
 */
@RestController
@RequestMapping("/v1/api/logData")
@Validated
public class LogDataController extends BaseController<LogData> {

    @Autowired
    private ILogDataService logDataService;

    @ApiOperation(value = "根据操作日志ID分页查询操作数据记录",notes = "传入分页数据,操作日志ID(guidOperate)作为参数")
    @PostMapping("/listByOperateId")
    public ResultVO list(@RequestBody @Validated Query<LogData> query) {
        return  ResultVO.success("查询成功", logDataService.queryPageById(query.getPageObj(),query.getWrapper()));
    }

    @ApiOperation(value = "根据GUID查询操作数据记录",notes = "传入操作数据记录的guid作为参数")
    @GetMapping("/{id}")
    public ResultVO detial(@PathVariable @NotBlank(message = "guid不能为空") String id){
        LogData logAbfData = logDataService.selectById(id);
        if (logAbfData == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功",logAbfData);
    }

    @ApiOperation(value = "根据数据GUID查询操作数据记录",notes = "传入分页数据,数据GUID(dataGuid)作为参数")
    @PostMapping("/list")
    public ResultVO listByDataId(@RequestBody @Validated Query<LogData> query){
        return ResultVO.success("查询成功", logDataService.selectPage(query.getPageObj(),query.getWrapper()));
    }

}
